package run.vue.iblog.controller;

import cn.hutool.core.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import run.vue.iblog.common.Result;
import run.vue.iblog.common.ResultFactory;
import run.vue.iblog.service.BlogService;
import run.vue.iblog.service.BookService;
import run.vue.iblog.service.UserService;

import java.util.ArrayList;
import java.util.List;

@RestController
public class GlobalDataController {

    @Autowired
    private BlogService blogService;

    @Autowired
    private BookService bookService;

    @Autowired
    private UserService userService;

    @GetMapping("/alldata")
    public Result getSysData(){
        /**
         * 获取文章总数
         * @return
         */

        List<String> link = new ArrayList<>();
        List<Integer> datas = new ArrayList<>();

        int blogTotal = blogService.getTotalCount();
        Assert.notNull(blogTotal,"暂时没有博文");
//        AllDataDto blog = new AllDataDto("博客",blogTotal,blogTotal,true);
        link.add("博客数");
        datas.add(blogTotal);

        Integer bookTotal = bookService.getTotalBooks();
        Assert.notNull(bookTotal ,"暂时没有图书");
//        AllDataDto book = new AllDataDto("书籍",bookTotal,bookTotal,true);
        link.add("书籍数");
        datas.add(bookTotal);

        int userTotal = userService.getTotalCount();
        Assert.notNull(userTotal,"暂时没有用户");
//        AllDataDto users = new AllDataDto("用户",userTotal,userTotal,true);
        link.add("用户数");
        datas.add(userTotal);

        int activeUserTotal = userService.getActiveCount();
        System.out.println(activeUserTotal);
        Assert.notNull(activeUserTotal,"暂时没有活跃用户");
//        AllDataDto activeUser = new AllDataDto("博客",activeUserTotal,activeUserTotal,true);
        link.add("活跃用户");
        datas.add(activeUserTotal);
        List res = new ArrayList();
        res.add(link);
        res.add(datas);

        return ResultFactory.success("获取数据成功",res);
    }
}
